package com.zjw.xm.xmuser.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zjw.xm.entity.CrBook;
import com.zjw.xm.entity.CrUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author zjw1
 * @since 2022-08-03
 */
@Mapper
public interface CrUserMapper extends BaseMapper<CrUser> {
    @Select("select * from cr_user where id=#{id}")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "id", property = "crBooks",
                    many = @Many(select = "selectCrBookByCart")),
    })
    CrUser selectWithId(int id);

    @Select("select * from cr_book a join cr_cart b on a.id=b.bid" +
            " where b.uid=#{id} ")
    List<CrBook> selectCrBookByCart(int id);



    @Select("select * from cr_user where id=#{id}")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "id", property = "crBooks",
                    many = @Many(select = "selectCrBookByOrder")),
    })
    CrUser selectOrderWithId(int id);

    @Select("select * from cr_book a join cr_bought b on a.id=b.bid" +
            " where b.uid=#{id} ")
    List<CrBook> selectCrBookByOrder(int id);



    @Delete("delete from cr_cart where uid =#{uid} and bid=#{bid}")
    void deleteCartByid(int uid,int bid);
}
